﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Xml;
using System.Xml.Serialization;
using DefectDBTypes;

namespace Defecter.Contract
{
	[Flags]
	public enum UserRole
	{
		None = 0,					// effetely disables a user
		Customer = 1,
		Manager = 2,
		Developer = 4,
		Tester = 8,
	}

	public enum RecordAction
	{
		Read,
		Insert,
		Update,
		Remove,
	}

	#region Interface IClientContract
	[ServiceContract(CallbackContract=typeof(IClientCallbackContract))]
	[WCFFaultHandlerAttribute(typeof(WCFFaultHandler))]
	public interface IClientContract
	{
		#region People
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Client> GetClients (Guid sessionId, string [] includeRelations);

		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Developer> GetDevelopers (Guid sessionId, string[] includeRelations);

		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Manager> GetManagers (Guid sessionId, string[] includeRelations);

		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Person> GetPeople (Guid sessionId, string[] includeRelations);

		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		void UpdatePerson (Guid sessionId, Person updatedPerson);
		#endregion

		#region Housekeeping
		/// <summary>
		/// Creates an entry in the session table on the server
		/// </summary>
		/// <param name="sessionId"></param>
		/// <returns></returns>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string Attach (out Guid sessionId);

		/// <summary>
		/// Releases the session id and associated information in the server
		/// </summary>
		/// <param name="sessionId"></param>
		/// <returns></returns>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string Detach (Guid sessionId);
		#endregion

		#region Trouble_Reports
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Trouble_Report> GetTroubleReports (Guid sessionId, string ownerType,
			string [] includedRelations);

		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Trouble_Report> GetTroubleReportsBy (Guid sessionId,
			IObjectWithChangeTracker associatedEntity);
#if false
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		List<Trouble_Report> GetTroubleReportsFrom (Guid sessionId, string objectSetType);
#endif
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		void UpdateTroubleReport (Guid sessionId, Trouble_Report updatedReport);

		#endregion

		#region
		/// <summary>
		/// Changes the password for the currently logged on user
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="currentPassword"></param>
		/// <param name="newPassword"></param>
		/// <returns>null if successful; otherwise error message</returns>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string ChangePassword (Guid sessionId, string userId, string currentPassword,
			string newPassword);

		/// <summary>
		/// Logs off the current user
		/// </summary>
		/// <returns>null if successful; otherwise error message</returns>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string Logoff (Guid sessionId);

		/// <summary>
		/// Logs on a user
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="password"></param>
		/// <param name="userRole"></param>
		/// <returns>null if successful; otherwise error message</returns>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string Logon (Guid sessionId, string userId, string password, out UserRole userRole);

		/// <summary>
		/// Used by an manager to perform user maintenance
		/// </summary>
		/// <param name="action"></param>
		/// <param name="userId"></param>
		/// <param name="newPassword"></param>
		/// <param name="role"></param>
		/// <returns>null if successful; otherwise error message</returns>
		/// <remarks>
		/// Only the role and email address may be retrieved
		/// Password, role and email address may be updated
		/// </remarks>
		[OperationContract]
		[FaultContractAttribute(typeof(WCFFault))]
		string UserIdMaintance (Guid sessionId, RecordAction action, string userId,
			string newPassword, ref string emailAddress, ref UserRole role);
		#endregion
	}			/* interface IClientContract */
	#endregion
	
}